package com.cci.kangdao.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.cci.kangdao.service.GMApplyRecordTService;
import com.cci.kangdao.utilTool.ParameterTool;

/**
 * GM申请记录controller
 *
 */
@Controller
public class GMApplyRecordTController {
	
	private Logger log = Logger.getLogger(this.getClass().getName());
	
	@Autowired
	private GMApplyRecordTService gmApplyRecordTService;

	//查看当前用户GM权限申请记录
	@RequestMapping("/getGMRecordList.aspx")
	public ModelAndView getGMRecordList(HttpServletRequest request,
														   HttpServletResponse response) throws Exception {
		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			return gmApplyRecordTService.getGMRecordList(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);
			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);
		}
		return null;
	}

	//查看当前用户GM权限申请记录详情
	@RequestMapping("/getGMApplyDetail.aspx")
	public ModelAndView getGMApplyDetail(HttpServletRequest request,
										HttpServletResponse response) throws Exception {
		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			return gmApplyRecordTService.getGMApplyDetail(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);
			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);
		}
		return null;
	}

	//用户撤回申请
	@RequestMapping("/withdrawApply.aspx")
	public ModelAndView withdrawApply(HttpServletRequest request,
										 HttpServletResponse response) throws Exception {
		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			return gmApplyRecordTService.withdrawApply(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);
			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);
		}
		return null;
	}

	//用户提醒审核人
	@RequestMapping("/remindAudit.aspx")
	public ModelAndView remindAudit(HttpServletRequest request,
									  HttpServletResponse response) throws Exception {
		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			return gmApplyRecordTService.remindAudit(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);
			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);
		}
		return null;
	}


	//GM权限管理列表接口
	@RequestMapping("/getGMApplyList.aspx")
	public ModelAndView getGMApplyList(HttpServletRequest request,
									HttpServletResponse response) throws Exception {
		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			return gmApplyRecordTService.getGMApplyList(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);
			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);
		}
		return null;
	}


	//根据GM的Id更改为该id已读
	@RequestMapping("/updateGMMsgIsReadById.aspx")
	public ModelAndView updateGMMsgIsRead(HttpServletRequest request,
										  HttpServletResponse response) throws Exception {
		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			return gmApplyRecordTService.updateGMMsgIsReadById(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);
			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);
		}
		return null;
	}


	//拒绝申请接口
	@RequestMapping("/refuseApply.aspx")
	public ModelAndView refuseApply(HttpServletRequest request,
									   HttpServletResponse response) throws Exception {
		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			return gmApplyRecordTService.refuseApply(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);
			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);
		}
		return null;
	}


	//INSITE订单列表
	@RequestMapping("/getINSITEOrderList.aspx")
	public ModelAndView getINSITEOrderList(HttpServletRequest request,
										HttpServletResponse response) throws Exception {
		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			return gmApplyRecordTService.getINSITEOrderList(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);
			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);
		}
		return null;
	}


	//GM权限申请消息列表
	@RequestMapping("/getGMMsgList.aspx")
	public ModelAndView getGMMsgList(HttpServletRequest request, HttpServletResponse response) throws Exception {
		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			return gmApplyRecordTService.getGMMsgList(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);
			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);
		}
		return null;
	}

	
	/**
	 * Guidanz需求
	 * 返回当前用户的未过期的GM权限
	 */
	@RequestMapping("/getUserGMLevel.aspx")
	@ResponseBody
	public void getUserGMLevel(HttpServletRequest request, HttpServletResponse response) {
		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			gmApplyRecordTService.getUserGMLevel(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);
			ParameterTool.writeErrorResponse(response);
		}
	}
	
	
	/**
	 * Guidanz需求
	 * 返回渠道列表
	 */
	@RequestMapping("/getCompanyList.aspx")
	@ResponseBody
	public void getCompanyList(HttpServletRequest request, HttpServletResponse response) {
		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			gmApplyRecordTService.getCompanyList(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);
			ParameterTool.writeErrorResponse(response);
		}
	}
	
	
	/**
	 * Guidanz需求
	 * 返回某个渠道下的所有服务站
	 */
	@RequestMapping("/getServiceStationByCompanyId.aspx")
	@ResponseBody
	public void getServiceStationByCompanyId(HttpServletRequest request, HttpServletResponse response) {
		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			gmApplyRecordTService.getServiceStationByCompanyId(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);
			ParameterTool.writeErrorResponse(response);
		}
	}
	
	
	/**
	 * Guidanz需求
	 * 申请Guidanz权限
	 */
	@RequestMapping(value = "/applyLevels.aspx", method = RequestMethod.POST)
	@ResponseBody
	public void applyLevels(HttpServletRequest request, HttpServletResponse response) {
		try{
			Map<String, Object> map = ParameterTool.getRequestBody(request);
			map.put("response", response);
			gmApplyRecordTService.applyLevels(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);
			ParameterTool.writeErrorResponse(response);
		}
	}
	
	
	
	/**
	 * Guidanz H5
	 * 用户修改权限申请单
	 */
	@RequestMapping(value = "/userUpdateApplyRecord.aspx", method = RequestMethod.POST)
	@ResponseBody
	public void userUpdateApplyRecord(HttpServletRequest request, HttpServletResponse response) {
		try{
			
			Map<String, Object> map = ParameterTool.getRequestBody(request);
			map.put("response", response);
			gmApplyRecordTService.userUpdateApplyRecord(map);
		}catch(Exception ex){
			
			log.error(ex.getMessage(),ex);
			ParameterTool.writeErrorResponse(response);
		}
	}
	
	
	

	/**
	 * Guidanz需求
	 * 撤回Guidanz权限审核记录
	 */
	@RequestMapping("withdrawApplyRecord.aspx")
	@ResponseBody
	public void withdrawApplyRecord(HttpServletRequest request,  HttpServletResponse response) {
		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			gmApplyRecordTService.withdrawApplyRecord(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);
			ParameterTool.writeErrorResponse(response);
		}
	}
	
	
	/**
	 * Guidanz需求
	 * Guidanz申请记录列表
	 */
	@RequestMapping("applyRecordList.aspx")
	@ResponseBody
	public void applyRecordList(HttpServletRequest request,  HttpServletResponse response) {
		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			gmApplyRecordTService.applyRecordList(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);
			ParameterTool.writeErrorResponse(response);
		}
	}

	/**
	 * Guidanz需求
	 * Guidanz记录详情
	 */
	@RequestMapping("applyRecordDetail.aspx")
	@ResponseBody
	public void applyRecordDetail(HttpServletRequest request,  HttpServletResponse response) {
		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			gmApplyRecordTService.applyRecordDetail(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);
			ParameterTool.writeErrorResponse(response);
		}
	}
	
	
	/**
	 * Guidanz需求
	 * 分公司列表
	 */
	@RequestMapping("/getSubstationList.aspx")
	@ResponseBody
	@Deprecated
	public void getSubstationList(HttpServletRequest request,  HttpServletResponse response) {
		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			gmApplyRecordTService.getSubstationList(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);
			ParameterTool.writeErrorResponse(response);
		}
	}
	
	//================================================Guidanz 站长审核======================================================
	
	/**
	 * Guidanz H5
	 * 站长待审核列表
	 */
	@RequestMapping("stationAuditList.aspx")
	@ResponseBody
	public void stationAuditList(HttpServletRequest request,  HttpServletResponse response) {
		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			gmApplyRecordTService.stationAuditList(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);
			ParameterTool.writeErrorResponse(response);
		}
	}
	
	
	
	/**
	 * Guidanz H5
	 * 站长通过或驳回申请单
	 */
	@RequestMapping("stationApproveOrRefuseRecord.aspx")
	@ResponseBody
	public void stationApproveOrRefuseRecord(HttpServletRequest request,  HttpServletResponse response) {
		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			gmApplyRecordTService.stationApproveOrRefuseRecord(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);
			ParameterTool.writeErrorResponse(response);
		}
	}	
	
	

}
